package studio.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import com.mysql.jdbc.PreparedStatement;

import studio.excepcion.DAOExcepcion;
import studio.modelo.InstBasico;
import studio.util.ConexionBD;

public class InstBasicoDAO extends BaseDAO{

	public Collection <InstBasico> insertarInstBas(InstBasico objInstBasico) throws DAOExcepcion {
		System.out.println("InstrumentoDAO: insertar(InstBasico)");
		String query = "INSERT INTO SalaArm_Instrumento( Sala_Armada_idSalaArmada, Instrumento_idInstrumento,TipoRecurso_idTipoRecurso) VALUES (?,?,?)";
		Collection<InstBasico> lista = new ArrayList<InstBasico>();
		Connection con = null;
		PreparedStatement stmt = null;
		//ResultSet rs = null
		try {
			con = ConexionBD.obtenerConexion();
			stmt = (PreparedStatement) con.prepareStatement(query);			
			stmt.setInt(1,objInstBasico.objSalArm.getIdSalaArmada());			
			stmt.setInt(2,objInstBasico.objInst.getIdInstrumento());
			stmt.setInt(3,objInstBasico.objTipRecur.getIdTipoRecurso());
			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
			else
			{
				System.out.println("registrado Ok");
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);		
}
		return lista;
	}
	
}
